package com.ot.flink.cdc.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author: admin
 * @date: 2024/5/24
 * @since JDK1.8 version: 1.0.0
 */
@Component
public class SpringUtil implements ApplicationContextAware {

    public static ApplicationContext application;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        application = applicationContext;
    }

    /**
     * 通过name获取 Bean.
     * @param name
     * @return
     */
    public static <T>  T getBean(String name){
        return (T)application.getBean(name);
    }

    /**
     * 通过class获取class下的全部Bean.
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T> T getBean(Class<T> clazz){
        return application.getBean(clazz);
    }
}
